package com.example.websocketdemo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/video")
public class VideoSurveillanceController {
    @GetMapping("/videoRoaming")// 视频漫游
    public void videoRoaming(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction", "manyou");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }

    @GetMapping("/monitorTheWall")  // 监控墙
    public void monitorTheWall(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction", "jiankongqiang");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }

    @GetMapping("/suspend")  // 暂停
    public void suspend(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction", "pausemanyou");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }

    @PostMapping("/speed")  //速度
    public String speed(String value, HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject_one = new JSONObject();
        jsonObject.put("instruction", "manyouspeed");
        System.out.println("value");
        jsonObject_one.put("speed", value);
        jsonObject.put("param", jsonObject_one);
        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
        return value;
    }


    @GetMapping("/monitoring")
    public void monitoring(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject jsonObject_one = new JSONObject();
        jsonObject_one.put("instruction", "resetpoi");
        WebSocketTest.sendInfo(jsonObject_one.toJSONString(), "connect");

        JSONObject jsonObject = new JSONObject();
        JSONObject json = new JSONObject();
        jsonObject.put("instruction", "showpoi");
        json.put("showtype", "group");
        json.put("poigroup", "shipinjiankong");
        json.put("poitype", "shipinjiankong");
        jsonObject.put("param", json);
        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }
}
